package com.gemfire.onlineretailer.domain;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;

public class Electronics extends Item implements DataSerializable {

	  public static final long ELECTRONICS_1 = 10000001;
	  public static final long ELECTRONICS_2 = 10000002;

	  public static final long ELECTRONICS_3 = 10000003;
	  public static final long ELECTRONICS_4 = 10000004;
	  public static final long ELECTRONICS_5 = 10000005;
	  
	  public static final String ELECTRONICS_1_CODE = "10000001";
	  public static final String ELECTRONICS_2_CODE = "10000002";

	  public static final String ELECTRONICS_3_CODE = "10000003";
	  public static final String ELECTRONICS_4_CODE = "10000004";
	  public static final String ELECTRONICS_5_CODE = "10000005";
		  
	  public static final float ELECTRONICS_1_ORIGNAL_PRICE = 28.00f;
	  public static final float ELECTRONICS_2_ORIGNAL_PRICE = 30.00f ;
	  public static final float ELECTRONICS_3_ORIGNAL_PRICE = 32.00f;
	  public static final float ELECTRONICS_4_ORIGNAL_PRICE = 34.00f;
	  public static final float ELECTRONICS_5_ORIGNAL_PRICE = 36.00f;
	  
	
	  
	  
	private int electronicsType;
	private String tvSize;
	private Vendor vendor;
	private int hardDiskSize;
	private int memorySize;
	private boolean diskDrivePresent;
	private int numUSBPort;
	private float price;
	
	public Electronics(){
		super();
	}
	public int getElectronicsType() {
		return electronicsType;
	}

	public void setElectronicsType(int electronicsType) {
		this.electronicsType = electronicsType;
	}

	public String getTvSize() {
		return tvSize;
	}

	public void setTvSize(String tvSize) {
		this.tvSize = tvSize;
	}

	public Vendor getVendor() {
		return vendor;
	}

	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
	}

	public int getHardDiskSize() {
		return hardDiskSize;
	}

	public void setHardDiskSize(int hardDiskSize) {
		this.hardDiskSize = hardDiskSize;
	}

	public int getMemorySize() {
		return memorySize;
	}

	public void setMemorySize(int memorySize) {
		this.memorySize = memorySize;
	}

	public boolean isDiskDrivePresent() {
		return diskDrivePresent;
	}

	public void setDiskDrivePresent(boolean diskDrivePresent) {
		this.diskDrivePresent = diskDrivePresent;
	}

	public int getNumUSBPort() {
		return numUSBPort;
	}

	public void setNumUSBPort(int numUSBPort) {
		this.numUSBPort = numUSBPort;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}


	
	@Override
	public void fromData(DataInput in) throws IOException,
			ClassNotFoundException {
		this.electronicsType = in.readInt();
		this.tvSize = in.readUTF();
		this.vendor =  (Vendor) DataSerializer.readObject(in);
		this.hardDiskSize = in.readInt();
		this.memorySize = in.readInt();
		this.diskDrivePresent = in.readBoolean();
		this.numUSBPort = in.readInt();
		this.price = in.readFloat();
		
	}

	@Override
	public void toData(DataOutput out) throws IOException {
		out.writeInt(this.electronicsType);
		out.writeUTF(this.tvSize);
		DataSerializer.writeObject(this.vendor, out);
		out.writeInt(this.hardDiskSize);
		out.writeInt(this.memorySize);
		out.writeBoolean(this.diskDrivePresent);
		out.writeInt(this.numUSBPort);
		out.writeFloat(this.price);
	}
	
public static Electronics createInstance(long electronicsId){
		
		/*
		 * Use itemId to read from DB or from other source, Hardcode for now
		 */
		
		Electronics electronics = new Electronics();
		
		if (electronicsId == ELECTRONICS_1){
			electronics.setItemId(ELECTRONICS_1);
			electronics.setElectronicsType(ElectronicsType.TV.getCode());
			electronics.setItemCode(ELECTRONICS_1_CODE);
			electronics.setItemName("60 inch TV");
			electronics.setPrice(29999.00f);
		} 
		else if (electronicsId == ELECTRONICS_2){
			electronics.setItemId(ELECTRONICS_2);
			electronics.setElectronicsType(ElectronicsType.COMPUTER.getCode());
			electronics.setItemCode(ELECTRONICS_2_CODE);
			electronics.setItemName("Desktop");
			electronics.setPrice(599.00f);
		} 
		else if (electronicsId == ELECTRONICS_3){
			electronics.setItemId(ELECTRONICS_3);
			electronics.setElectronicsType(ElectronicsType.LAPTOP.getCode());
			electronics.setItemCode(ELECTRONICS_3_CODE);
			electronics.setItemName("Apple MacBook Pro");
			electronics.setPrice(999.00f);
		} 
		else if (electronicsId == ELECTRONICS_4){
			electronics.setItemId(ELECTRONICS_4);
			electronics.setElectronicsType(ElectronicsType.iPAD.getCode());
			electronics.setItemCode(ELECTRONICS_4_CODE);
			electronics.setItemName("iPad 32 GB");
			electronics.setPrice(499.00f);
		}
		else {
			electronics.setItemId(ELECTRONICS_5);
			electronics.setElectronicsType(ElectronicsType.SMARTPHONE.getCode());
			electronics.setItemCode(ELECTRONICS_5_CODE);
			electronics.setItemName("HTC Android");
			electronics.setPrice(399.00f);
	
			} 
		
		return electronics;
		
	}

}
